package aspectjutil.eventmanager;

import java.lang.reflect.Method;

import junit.framework.Assert;

import org.junit.Test;
import org.slf4j.LoggerFactory;

public class EventHandlerTestWithChildEventRecipient3 extends EventHandlerTestTemplate {
	static {
		logger = LoggerFactory.getLogger( EventHandlerTestWithChildEventRecipient3.class);
	}
	
	// Tests about  @EventTrigger inheritance -----------------------------------------------------
	@Test
	public void testEventProducerMethodInheritance3() throws Throwable {
		// Instantiate EventRecipient object ------------------------------------------------------
		Object eventRecipientObj 
		= EventManagerTestUtils.eventRecipientFactory( childDelegationClassLoader);
		// ----------------------------------------------------------------------------------------
		
		// Instantiate ChildEventRecipient3 object --------------------------------------------
		// ChildEventRecipient3 is not extention of EventRecipient
		Object childEventRecipient3Obj 
		= EventManagerTestUtils.childEventRecipient3Factory( childDelegationClassLoader);
		// ----------------------------------------------------------------------------------------
		
		// Execute ChildEventProducer3.calculate method -------------------------------------------
		Object childEventProducer3Obj 
		= EventManagerTestUtils.childEventProducer3Factory( childDelegationClassLoader);
		Method calculateMethod 
		= EventManagerTestUtils.getEventProducerCalculateMethod( childEventProducer3Obj.getClass());
		Integer calculationResult = (Integer)calculateMethod.invoke( childEventProducer3Obj, 4, 8);
		// ----------------------------------------------------------------------------------------
		
		// Verifications --------------------------------------------------------------------------
		Assert.assertEquals( 
				EventManagerTestUtils.getEventTraceListDump( eventTraceList) + "\n", 
				1, 
				eventTraceList.size()
				);
			Assert.assertTrue(
					EventManagerTestUtils.getEventTraceListDump( eventTraceList), 
					eventTraceList.get( 0)
					.contains(
							EventManagerTestUtils.ChildEventRecipient3ClassName
							+ ".onOverridenCalculationEvent"
							) 
					);
			int eventTraceIndex = 0;
			Assert.assertEquals( 
					EventManagerTestUtils.getOverridenCalculationEventClass( childDelegationClassLoader), 
					triggeredEventTraceList.get( eventTraceIndex)
					);
			Class<?> eventerInfoClass 
			= EventManagerTestUtils.getEventerInfoClass( childDelegationClassLoader);
			Object eventerInfo = eventerInfoClass.cast( eventerTraceList.get( eventTraceIndex));
				Assert.assertEquals( 
						EventManagerTestUtils.getEventerObjOfEventerInfo( eventerInfo),
						childEventProducer3Obj
						);
				Assert.assertEquals( 
						EventManagerTestUtils.getEventerMethodOfEventerInfo( eventerInfo).getName(),
						"calculate"
						);
			Assert.assertEquals( 
					(Integer)eventResultTraceList.get( eventTraceIndex), 
					calculationResult
					);
		// ----------------------------------------------------------------------------------------
	} // public void testEventProducerMethodInheritance3()
	// --------------------------------------------------------------------------------------------
}
